import Vue from 'vue'

const userCreateModal = (Component, options) => {
  const FeatureConstructor = Vue.extend(Component)
  const instance = new FeatureConstructor({
    propsData: options
  })
  // 获取组件的元素id/className
  const el = instance.$mount().$el
  document.body.appendChild(el)
  // 移除组件
  const remove = () => {
    document.body.removeChild(el)
  }
  // 暴露一个updateProps方法--更新props方法
  const $updateProps = (props) => {
    props && Object.keys(props).forEach(k => {
      instance[k] = props[k]
    })
  }
  instance.remove = remove
  instance.$updateProps = $updateProps
}

if (window.Vue) {
  window.userCreateModal = userCreateModal
  Vue.use(userCreateModal)
}

export default userCreateModal
